package mua.core.operation.other;

import mua.core.operation.list.Run;
import mua.core.value.Bool;
import mua.core.value.Expression;
import mua.core.value.FunctionBody;
import mua.core.value.MuaValue;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;

public class Load {
    public static MuaValue run(MuaValue a,Scanner scanner, FunctionBody functionBody) {
        //最后还是通过了Run来实现
        String fileName = "./" + a.toString();
        try {
            FileReader fr = new FileReader(fileName);
            BufferedReader br = new BufferedReader(fr);
            String line;
            StringBuilder one = new StringBuilder("[");
            while ((line = br.readLine()) != null) {
                one.append(line).append(" ");
//                brackets.clear();
//                //判断该行的中括号是否闭合
//                for(int i=0;i<one.length();i++){
//                    if(one.charAt(i)=='"'&&brackets.isEmpty()){
//                        while (one.charAt(++i)!=' '&&i<one.length());
//                    }
//                    else if(one.charAt(i)=='[')brackets.push(true);
//                    else if(one.charAt(i)==']'){
//                        brackets.pop();
//                        if(brackets.empty())break;
//                    }
//                }
//                if(brackets.empty()){
//                    arrs = mySplit(one.toString());
//                    for(int i=0;i<arrs.size();i++){
//                        if(arrs.get(i).equals("make")){
//                            Make.run(new Word(arrs.get(++i).substring(1)), judgeType(arrs.get(++i), functionBody), functionBody);
//                        }
//                    }
//                    one = new StringBuilder();
//                }
            }
            one.append("]");
            Run.run(new Expression(one.toString()),scanner,functionBody);
            br.close();
            fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Bool("true");
    }
}
